﻿#include "cat-app.hpp"
#include "catimgui.h"
#include <thread>
#include <string>

namespace {
	
	static int port = 0;

}

namespace {
	//渲染线程
	static void RenderProcess(void (*CallBack)()) {

		catimgui::Run(port);
		if (CallBack) {
			CallBack();
		}
	}
	static bool isRun = true;
	void RenderEndCallBack() {
		isRun = false;
	}
}

CATApp::CATApp(int argc, char* argv[])
{
	port = std::stoi(argv[1]);
	printf("debug :%d \n", port);
}

CATApp::~CATApp()
{
}

bool CATApp::APPInit()
{
	return true;
}

int CATApp::Run()
{	
	std::thread rp(RenderProcess, RenderEndCallBack);
	

	while (isRun) {		
		std::this_thread::sleep_for(std::chrono::seconds(1));
	}

	rp.join();
	return 0;
}
